<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/7/27 0027
 * Time: 14:47
 */
namespace Admin\Models;

use Phalcon\Di;
use Helpers\Main;

//GET /api/v1/dictionaries
class InterfaceService extends BaseModel
{

    const InterfaceService = 'resServerInterface';

    /**
     * #方法说明：题库数据层
     * # Created by zsc
     */
    public function initialize()
    {
        parent::initialize();
    }

    /**
     * #方法说明：调用接口配置
     * @return mixed
    # Created by zsc
     */
    public static function runInterfaceConfig()
    {
        return Main::getConfigByName(self::InterfaceService);
    }

    /**
     * #方法说明：返回缓存配置设置
     * @return mixed
    # Created by zsc
     */
    public static function cache()
    {
        return Di::getDefault()->get('cache');
    }

    /**
     * #方法说明：产生接口Url
     * @param $httpUrl
     * @param array $paramArr
     * @return bool|string
    # Created by zsc
     */
    public static function createInterfaceUrl($httpUrl, $paramArr = array(), $interfaceKey = null)
    {
        if (!$httpUrl) return false;
        $getParamArr = array();
        if ($paramArr) foreach ($paramArr as $key => $value) {
            strpos($httpUrl, '{' . $key . '}') ? $httpUrl = str_replace('{' . $key . '}', $value, $httpUrl) : $getParamArr[$key] = $value;
        }
        if ($getParamArr) {
            $httpUrl .= '?' . (is_array($getParamArr) ? http_build_query($getParamArr) : $getParamArr);
        }
        return self::runInterfaceConfig()[$interfaceKey] . $httpUrl;
    }
}